package com.bainuo.doctor.common.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.ImageView;

import com.bainuo.doctor.common.util.DisplayUtil;

/**
 * Created by bainuo on 2018/3/21.
 */

@SuppressLint("AppCompatCustomView")
public class CustomRangImageView extends ImageView{


    private Context context;
    public CustomRangImageView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
    }

    public CustomRangImageView(Context context) {
        super(context);
    }


    @Override
    protected void onDraw(Canvas canvas) {




            if (getWidth() == 0) return;


            int width = getWidth();
            int height = getHeight();
            int r = DisplayUtil.dip2px(context,6);

            Bitmap bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
            Canvas cv = new Canvas(bitmap);
            super.onDraw(cv);



        Bitmap bitmap1 = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
        Canvas cv1 = new Canvas(bitmap1);


//            canvas.saveLayerAlpha(0, 0, getWidth(), getHeight(), 255, Canvas.ALL_SAVE_FLAG);


        cv1.drawARGB(0,0,0,0);
            Paint paint = new Paint();
//            paint.setStyle(Paint.Style.FILL);
            paint.setARGB(255,0,0,255);
//            cv.drawRoundRect(new RectF(0,0,200,200),r,r,paint);

        cv1.drawRoundRect(new RectF(0,0,200,200),30,30,paint);


            paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        paint.setARGB(255,0,255,0);
//        cv1.drawRoundRect(new RectF(100,100,300,300),30,30,paint);

        cv1.drawBitmap(bitmap,0,0,paint);


        canvas.drawARGB(255,255,0,0);
        canvas.drawBitmap(bitmap1,0,0,new Paint());

//        canvas.restore();


//            bitmap.recycle();
    }


}
